(load-file "~/.emacs.d/elisp/remember-2.0/remember.el")
(require 'remember)

(org-remember-insinuate)
(setq org-directory "~/.org/")
(setq org-default-notes-file (concat org-directory "/upgradekit.org"))
(setq org-agenda-ndays 7)
(setq org-deadline-warning-days 14)
(setq org-agenda-show-all-dates t)
(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-start-on-weekday nil)
(setq org-enforce-todo-dependencies t)
;; (setq org-enforce-todo-checkbox-dependencies t)
(setq org-agenda-dim-blocked-tasks t)
;; include entries from the Emacs diary into Org mode's agenda
;; (setq org-agenda-include-diary t)

;; list only the highest level TODO headline and omit the sublevels from the global list
;; (setq org-agenda-todo-list-sublevels t)

;; The corresponding in-buffer setting is: #+STARTUP: lognotedone
;; (setq org-log-done 'note)

;; The corresponding in-buffer setting is: #+STARTUP: logdone
(setq org-log-done 'time)

(setq org-clock-persist t)
(org-clock-persistence-insinuate)



(define-key global-map "\C-cr" 'org-remember)
(global-set-key [f3] 'org-remember)
(global-set-key [C-f3] 'org-todo-list)
(global-set-key [M-f3] 'org-agenda-list)
(global-set-key [S-f3] 'org-tags-view)
;; (global-set-key [C-f1] 'org-todo-list)

(global-set-key "\C-c L" 'org-insert-link-global)
(global-set-key "\C-c o" 'org-open-at-point-global)


(setq org-remember-templates
      '(("Work" ?w "* TODO [#%^{Priority|B|A|C}] %^{Brief Description} %^g\nAdded: %U\n\n%?" "~/.org/work09.org" "FW")
        ("Uk" ?u "* TODO [#%^{Priority|B|A|C}] %^{Brief Description} %^g\nAdded: %U\n\n%?" "~/.org/upgradekit.org" "Universal")
        ("Table" ?t "* TODO [#%^{Priority|B|A|C}] %^{Brief Description} %^g\nAdded: %U\n\n%?" "~/.org/table.org" "T0")
        ("Bug" ?b "* BUG [#%^{Priority|B|A|C}] %^{Brief Description} %^g\nAdded: %U\n\n%?" "~/.org/upgradekit.org" "MV-M2")
        ("Study" ?s "* TODO [#%^{Priority|B|A|C}] %^{Brief Description} %^g\nAdded: %U\n\n%?" "~/.org/study09.org" "LKML")
        ("Idea" ?i "* IDEA [#%^{Priority|B|A|C}] %^{Brief Description} %^g\nAdded: %U\n\n%?" "~/.org/ideas.org" "IDEAS")
        ("Journal" ?j "* %U %?\n\n %i\n" "~/.org/JOURNAL.org")))


;; The common TODO sequence
(setq org-todo-keywords
      '((sequence "DEFERRED(f@/!)" "WAITING(w@/!)" "|")
        (sequence "BUG(B)" "INVESTIGATE(I@/!)" "TEST(T@/!)" "|" "CLOSED(C@/!)")
        (sequence "TODO(t)" "START(s@/!)" "|" "DONE(d@/!)")
        (sequence "IDEA(i)" "TRYING(y@/!)" "|" "ACHIEVE(a@/!)")
        (sequence "|" "CANCELED(c@/!)")
        (type "LinFeng"
              "JiangMin"
              "DaiWen"
              "WangYicheng"
              "MaShunYao"
              "CuiWei"
              "|"
              "FINISHED(F@/!)")))


(setq org-todo-keyword-faces
      '(("TODO"   . org-todo)
        ;; ("CANCELED"  . shadow)
        ("CANCELED"  . org-done)
        ("DONE"   . org-done)
        ("FINISHED"   . org-done)
        ;; ("DEFERRED"  . org-warning)
        ;; ("WAITING"  . org-warning)
        ("BUG"  . org-warning)
        ("INVESTIGATE"  . org-warning)
        ("TEST"  . org-warning)
        ("START"  . (:foreground "green" :weight bold))
        ("RESTART"  . (:foreground "green" :weight bold))
        ("DEFERRED"  . (:foreground "orange" :weight bold))
        ("WAITING"  . (:foreground "deepskyblue" :weight bold))
        ("LinFeng"  . (:foreground "yellow" :weight bold))
        ("JiangMin"  . (:foreground "yellow" :weight bold))
        ("DaiWen"  . (:foreground "yellow" :weight bold))
        ("WangYicheng"  . (:foreground "yellow" :weight bold))
        ("MaShunYao"  . (:foreground "yellow" :weight bold))
        ("CuiWei"  . (:foreground "yellow" :weight bold))
        ))


;; The following lines are always needed. Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c b") 'org-iswitchb)


;; (defun org-summary-todo (n-done n-not-done)
;;   "Switch entry to DONE when all subentries are done, to TODO otherwise."
;;   (let (org-log-done org-log-states)   ; turn off logging
;;     (org-todo (if (= n-not-done 0) "DONE" "TODO"))))

;; (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)



(defun gtd/uk ()
  (interactive)
  (find-file "~/.org/upgradekit.org")
  )
(defun gtd/work ()
  (interactive)
  (find-file "~/.org/work.org")
  )

(setq org-agenda-files (list "~/.org/table.org"
                             "~/.org/upgradekit.org"
                             "~/.org/work09.org"
                             "~/.org/study09.org"
                             "~/.org/ideas.org"))


;; (add-hook 'org-mode-hook 'turn-on-font-lock)

;; (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
;; (define-key mode-specific-map [?a] 'org-agenda)

;; (eval-after-load "org"
;; '(progn
;; (define-prefix-command 'org-todo-state-map)
;; (define-key org-mode-map "\C-cx" 'org-todo-state-map)
;; (define-key org-todo-state-map "x"
;; #'(lambda nil (interactive) (org-todo "CANCELLED")))
;; (define-key org-todo-state-map "d"
;; #'(lambda nil (interactive) (org-todo "DONE")))
;; (define-key org-todo-state-map "f"
;; #'(lambda nil (interactive) (org-todo "DEFERRED")))
;; (define-key org-todo-state-map "l"
;; #'(lambda nil (interactive) (org-todo "DELEGATED")))
;; (define-key org-todo-state-map "s"
;; #'(lambda nil (interactive) (org-todo "STARTED")))
;; (define-key org-todo-state-map "w"
;; #'(lambda nil (interactive) (org-todo "WAITING")))
;; (define-key org-agenda-mode-map "\C-n" 'next-line)
;; (define-key org-agenda-keymap "\C-n" 'next-line)
;; (define-key org-agenda-mode-map "\C-p" 'previous-line)
;; (define-key org-agenda-keymap "\C-p" 'previous-line)
;; ))

;; (load-file "~/.emacs.d/elisp/remember-2.0/remember.el")
;; (require 'remember)
;; (add-hook 'remember-mode-hook 'org-remember-apply-template)
;; (define-key global-map [(control meta ?r)] 'remember)
;; (custom-set-variables
;; '(org-agenda-files (quote ("~/todo.org")))
;; '(org-default-notes-file "~/notes.org")
;; '(org-agenda-ndays 7)
;; '(org-deadline-warning-days 14)
;; '(org-agenda-show-all-dates t)
;; '(org-agenda-skip-deadline-if-done t)
;; '(org-agenda-skip-scheduled-if-done t)
;; '(org-agenda-start-on-weekday nil)
;; '(org-reverse-note-order t)
;; '(org-fast-tag-selection-single-key (quote expert))
;; '(org-agenda-custom-commands
;; (quote (("d" todo "DELEGATED" nil)
;; ("c" todo "DONE|DEFERRED|CANCELLED" nil)
;; ("w" todo "WAITING" nil)
;; ("W" agenda "" ((org-agenda-ndays 21)))
;; ("A" agenda ""
;; ((org-agenda-skip-function
;; (lambda nil
;; (org-agenda-skip-entry-if (quote notregexp) "\\=.*\\[#A\\]")))
;; (org-agenda-ndays 1)
;; (org-agenda-overriding-header "Today's Priority #A tasks: ")))
;; ("u" alltodo ""
;; ((org-agenda-skip-function
;; (lambda nil
;; (org-agenda-skip-entry-if (quote scheduled) (quote deadline)
;; (quote regexp) "<[^>\n]+>")))
;; (org-agenda-overriding-header "Unscheduled TODO entries: "))))))
;; '(org-remember-store-without-prompt t)
;; '(org-remember-templates
;; (quote ((116 "* TODO %?\n %u" "~/todo.org" "Tasks")
;; (110 "* %u %?" "~/notes.org" "Notes"))))
;; '(remember-annotation-functions (quote (org-remember-annotation)))
;; '(remember-handler-functions (quote (org-remember-handler))))


